﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using Budget.DataAccess;
using Budget.DataAccess.Services;
using Budget.DataAccess.Repository;

namespace Budget.WCF
{
	// NOTE: If you change the class name "CategoryService" here, you must also update the reference to "CategoryService" in App.config.
	public class CategoryService : ICategoryService
	{
		private ICategoryDataService svc;

		#region ICategoryService Members

		public IList<Category> GetAll()
		{
			IList<Category> categories;

			if ( svc == null )
			{
				svc = new CategoryDataService( new BudgetRepository<Category>( new BudgetDataContext() ) );
			}
			categories = svc.GetAll();

			return categories;
		}

		public Category GetCategoryById( int ID )
		{
			Category category;

			if ( svc == null )
			{
				svc = new CategoryDataService( new BudgetRepository<Category>( new BudgetDataContext() ) );
			}
			category = svc.GetById( ID );

			return category;
		}

		public void Save( Category category )
		{
			// validation will go here

			svc = new CategoryDataService( new BudgetRepository<Category>( new BudgetDataContext() ) );
			svc.Save( category );
		}

		#endregion
	}
}
